import 'package:flutter/material.dart';

void main() {
  runApp(MainPage());
}
class MainPage extends StatelessWidget {
  const MainPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body:Container(
          alignment: Alignment.center,
          child:Column(
            children: [
              Text("父组件",style:TextStyle(fontSize: 20,color: Colors.black,),),
              ChildWidget(message:"父组件传过来的数据"),
              StatefulChildWidget(message:"父组件传过来的数据111"),
            ],
          ),
        )
      ),
    );
  }
}

//无状态子组件
class ChildWidget extends StatelessWidget {
  final String? message;
  const ChildWidget({Key? key,this.message}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child:Text("子组件-$message",style:TextStyle(fontSize: 20,color: Colors.red,),),

    );
  }
}

//有状态的子组件
class StatefulChildWidget extends StatefulWidget {
  final String message;
  const StatefulChildWidget({Key? key,required this.message}) : super(key: key);

  @override
  _StatefulChildWidgetState createState() => _StatefulChildWidgetState();
}

class _StatefulChildWidgetState extends State<StatefulChildWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child:Text("有状态的子组件-${widget.message}",style:TextStyle(fontSize: 20,color: Colors.red,),),
    );
  }
}

